#include "widget.h"
#include "ui_widget.h"
#include <QButtonGroup>
#include <QMessageBox>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    // 分组
    buttonGroup1 = new QButtonGroup(this);
    buttonGroup2 = new QButtonGroup(this);
    buttonGroup3 = new QButtonGroup(this);

    // 把上述单选按钮, 放到不同的组里.
    buttonGroup1->addButton(ui->radioButton_1);
    buttonGroup1->addButton(ui->radioButton_2);
    buttonGroup1->addButton(ui->radioButton_3);

    buttonGroup2->addButton(ui->radioButton_4);
    buttonGroup2->addButton(ui->radioButton_5);
    buttonGroup2->addButton(ui->radioButton_6);

    buttonGroup3->addButton(ui->radioButton_7);
    buttonGroup3->addButton(ui->radioButton_8);
    buttonGroup3->addButton(ui->radioButton_9);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QString message;
    // 提取三组的选择
    QButtonGroup* groups[] = {buttonGroup1, buttonGroup2, buttonGroup3};
    for (int i = 0; i < 3; ++i) {
        QAbstractButton* checkedButton = groups[i]->checkedButton();
        if (checkedButton) {
            message +=  QString::number(i + 1) + " " + checkedButton->text() + "\n";
        } else {
            message +=  QString::number(i + 1) + " 未选择\n";
        }
    }
    // 将选择作为提示框提交
    QMessageBox::information(this, "您选择的餐饮是", message);
}
